package solution.pointer;

/**
 * @author : wenchao.long
 * @date : Created in 2024-07-05 下午 11:03 周五
 * @description : 盛最多水的容器
 * 		<a href="https://leetcode.cn/problems/container-with-most-water/?envType=study-plan-v2&envId=top-100-liked">盛最多水的容器</a>
 */
public class No11 {

	public static int maxArea(int[] height) {
		int left = 0, right = height.length - 1;
		int max = 0;
		while (left < right) {
			// 获取最低高度
			int minHeight = Math.min(height[left], height[right]);
			// 获取面积
			max = Math.max(max, minHeight * (right - left));
			// 左移指针
			while (height[left] <= minHeight && left < right) {
				left++;
			}
			// 右移指针
			while (height[right] <= minHeight && left < right) {
				right--;
			}
		}
		return max;
	}

	public static void main(String[] args) {
		System.out.println(maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7}));
	}

}
